package com.game.autoTool.project.web.domain.resp;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @Author:
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> implements Serializable {


    //返回结果
    private T data;
    private Integer code;
    private String msg;


    public static <T> Result<T> succeed() {
        return of(null, HttpStatus.SUCCESS, "操作成功");
    }

    public static <T> Result<T> succeed(String msg) {
        return of(null, HttpStatus.SUCCESS, msg);
    }

    public static <T> Result<T> succeed(T model, String msg) {
        System.out.println("==接口返回值为==" + model + " 返回时间为:" + DateUtil.now());
        return of(model, HttpStatus.SUCCESS, msg);
    }

    public static <T> Result<T> succeed(T model, int code, String msg) {
        System.out.println("==接口返回值为==" + model + " 返回时间为:" + DateUtil.now());
        return of(model, code, msg);
    }

    public static <T> Result<T> succeed(T model) {
        System.out.println("==接口返回值为==" + JSON.toJSONString(model) + " 返回时间为:" + DateUtil.now());
        return of(model, HttpStatus.SUCCESS, "操作成功");
    }

    public static <T> Result<T> of(T datas, Integer code, String msg) {
        return new Result<>(datas, code, msg);
    }

    public static <T> Result<T> failed() {
        return of(null, HttpStatus.ERROR, "操作失败");
    }

    public static <T> Result<T> failed(String msg) {
        return of(null, HttpStatus.ERROR, msg);
    }

    public static <T> Result<T> failed(T model, String msg) {
        return of(model, HttpStatus.ERROR, msg);
    }

    public static <T> Result<T> failed(T model, int code, String msg) {
        return of(model, code, msg);
    }
}
